import Vue from 'vue'
import VueRouter from 'vue-router'
import homeRouter from './modules/homeRouter'
Vue.use(VueRouter)

const routes = [
    ...homeRouter
]

const router = new VueRouter({
    mode: 'history',
    routes
})

// 添加路由守卫
router.beforeEach((to, from, next) => {
    const token = localStorage.getItem('token') // 从LocalStorage中获取token
    const path = to.path.substring(1)
    if (path != "login" && token == null) {
        next('/login') // 登录页面的路由路径
    }
    next()
})

export default router